var swiper = null;
var viewlog = [];
var checklog = [];
var data_likefb = {};
var slide_index = null;
$(function () {
    $.ajaxSetup({async: true, cache: false});
    if ($(".swiper-container .swiper-slide").length > 1) {
        swiper = new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            effect: 'slide',
            autoplay: 0,
            speed: 600,
            lazyLoading: true,
            loop: false,
            onInit: function () {
                id_campaign = $(".swiper-slide-active").data("id");
                landing_page = $(".swiper-slide-active").data("landing_page");
                type_time_session = $(".swiper-slide-active").data("type_time_session");
                saveViewLog(id_campaign);

                checkFacebooklike(mac, id_campaign);
                checkEmail(mac, id_campaign);
                checkPhone(mac, id_campaign);
                checkLoginWifi(mac, id_campaign);
            },
            onSlideChangeEnd: function (e) {
                id_campaign = $(".swiper-slide-active").data("id");
                landing_page = $(".swiper-slide-active").data("landing_page");
                type_time_session = $(".swiper-slide-active").data("type_time_session");
                saveViewLog(id_campaign);

                checkFacebooklike(mac, id_campaign);
                checkEmail(mac, id_campaign);
                checkPhone(mac, id_campaign);
                checkLoginWifi(mac, id_campaign);
            }
        });
    } else {
        id_campaign = $(".swiper-slide").data("id");
        landing_page = $(".swiper-slide").data("landing_page");
        type_time_session = $(".swiper-slide").data("type_time_session");
        saveViewLog(id_campaign);

        //checkFacebooklike(mac, id_campaign);
        checkEmail(mac, id_campaign);
        checkPhone(mac, id_campaign);
        checkLoginWifi(mac, id_campaign);
    }

    /*Rate*/

    $(".ui-rate .stars a").on("tap", function (e) {
        var $this = $(this);
        var index = $this.index();
        var text = $this.data('text');
        var label = $this.parents('.ui-rate').find('.ui-label').text();
        var data = {
            label: label,
            value: text,
            fieldtype: "rate"
        };

        $this.parents('.ui-rate').attr('data-value', JSON.stringify(data))
                .find('.ui-rate_label span').text(text);
        var active = "active_" + $this.parents('.ui-rate').attr('id');
        $this.parent().find('a').each(function (i) {
            if (i <= index) {
                $(this).attr('class', 'active ' + active);
            } else {
                $(this).attr('class', '');
            }
        });
        var color = $(this).parent().find(".active").css('color');
        $this.parents('.ui-rate').find('.ui-rate_label').css("background", color).find('.arrow').css({'border-right-color': color});
        e.preventDefault();
    });

    if ($(".ui-rate_label").length > 0) {
        $(".ui-rate_label").each(function () {
            var color = $(this).prev().find('.active').css('color');
            if (color == undefined) {
                color = $(this).prev().find('a:first-child').css('color');
            }
            $(this).css("background", color);
            $(this).find(".arrow").css({'border-right-color': color});
        });
    }

    if ($(".fixed_center").length > 0) {
        $(".fixed_center").each(function () {
            $(this).height($(this).height()).addClass('fixed');
        });
    }
    if ($(".fixed_bottom").length > 0) {
        $(".fixed_bottom").each(function () {
            $(this).height($(this).height()).addClass('fixed');
        });
    }
});